package com.barbeque.mall.controller;

import com.barbeque.mall.bean.BaseRespVo;
import com.barbeque.mall.bean.stat.*;

import com.barbeque.mall.service.StatService;
import com.barbeque.mall.service.StatServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author why
 * @since 2022/07/18 15:32
 */
@RestController
@RequestMapping("admin/stat")
public class AdminStartController {
    @Autowired
    StatService statService;

    /**
     * 用户统计
     *
     * @return
     */
    @RequiresPermissions("admin:stat:user")
    @RequestMapping("user")
    public BaseRespVo user() {
        StatUser statUser = new StatUser();

        ArrayList<String> strings = new ArrayList<>();
        strings.add("day");
        strings.add("users");
        statUser.setColumns(strings);
        List<RowsDTO> data = statService.selectStatUser();
        statUser.setRows(data);
        BaseRespVo<StatUser> statUserBaseRespVo = new BaseRespVo<>();
        statUserBaseRespVo.setErrmsg("成功");
        return BaseRespVo.ok(statUser);
    }

    /**
     * 订单统计
     *
     * @return
     */
    @RequiresPermissions("admin:stat:order")
    @RequestMapping("order")
    public BaseRespVo order() {
        StatOrder statOrder = new StatOrder();

        ArrayList<String> strings = new ArrayList<>();
        strings.add("day");
        strings.add("orders");
        strings.add("customers");
        strings.add("amount");
        strings.add("pcr");
        statOrder.setColumns(strings);
        List<RowsOrders> ordersList = statService.selectStatOrder();
        statOrder.setRows(ordersList);
        BaseRespVo<StatOrder> statOrderBaseRespVo = new BaseRespVo<>();
        statOrderBaseRespVo.setErrmsg("成功");
        return BaseRespVo.ok(statOrder);
    }

    /**
     * 商品统计
     */
    @RequiresPermissions("admin:stat:goods")
    @RequestMapping("goods")
    public BaseRespVo goods() {
        StatGoods statGoods = new StatGoods();
        ArrayList<String> strings = new ArrayList<>();
        strings.add("day");
        strings.add("orders");
        strings.add("products");
        strings.add("amount");
        statGoods.setColumns(strings);
        List<RowsGoods> goodsList = statService.selectStatGoods();
        statGoods.setRows(goodsList);
        BaseRespVo<StatGoods> statGoodsBaseRespVo = new BaseRespVo<>();
        statGoodsBaseRespVo.setErrmsg("成功");
        return BaseRespVo.ok(statGoods);

    }
}
